package com.stlm2.controller;


import com.stlm2.dems.service.TiXianShenQingService;
import com.stlm2.util.codecontent.CodeContent;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.json.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;

/**
 * Created by ZLQ on 2017/6/15.
 */
@Controller
@RequestMapping("/tiXianC")
public class TiXianController {
    @Resource
    private TiXianShenQingService tiXianShenQingService;

    /*
*后台查询兑换记录列表
* token:用户token
* page:页码
* userName:用户名（用户登陆手机号）
* stateValue：状态值
* code:兑换记录编码
*
 */
    @ResponseBody
    @RequestMapping(value="/queryTiXianShenQingListCRM.json",produces="application/json;charset=UTF-8")
    public  String queryTiXianShenQingListCRM(ModelMap model,String token,String page,String userName,String stateValue,
                                              String code){
        String data=null;
        try {
            data=tiXianShenQingService.queryTiXianShenQingListCRM(model,token,page,userName,stateValue,code);
        }catch (Exception e){
            e.printStackTrace();
            return  CodeContent.getModelByCode(0,"获取记录列表失败",data);
        }
        return  data;
    }


    /*
*后台查询兑换记录详情
* token:用户token
* id:兑换记录ID
*/
    @ResponseBody
    @RequestMapping(value="/details.json",produces="application/json;charset=UTF-8")
    public  String details(ModelMap model,String token,String id){
        try {
            model=tiXianShenQingService.getDetails(model,token,id);
        }catch (Exception e){
            e.printStackTrace();
            model.put("code",0);
            model.put("msg","获取详情信息失败");
            return new JSONObject(model).toString();
        }
        return new JSONObject(model).toString();
    }


    /*
*后台审核兑换记录
* token:用户token
* id:兑换记录ID
* state:状态值 2：不通过 3 :通过
* note：备注
*/
    @ResponseBody
    @RequestMapping(value="/checkUpdate.json",produces="application/json;charset=UTF-8")
    public  String checkUpdate(ModelMap model,String token,String id,String stateValue,String note){
        String data=null;
        try {
            data=tiXianShenQingService.checkUpdateCRM( model,token,id,stateValue,note);
        }catch (Exception e){
            e.printStackTrace();
            return  CodeContent.getModelByCode(0,"获取详情信息失败",data);
        }
        return  data;
    }

    @RequestMapping(value="/WithdrawalAudit",produces="application/json;charset=UTF-8")
    public ModelAndView add(ModelAndView modelAndView){
        modelAndView.setViewName("/withdraw/WithdrawalAudit");
        return modelAndView;
    }

    @RequestMapping(value="/WithdrawalDetail",produces="application/json;charset=UTF-8")
    public ModelAndView edit(ModelAndView modelAndView){

        modelAndView.setViewName("/withdraw/withdrawDetail");
        return modelAndView;
    }


}
